#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
private:
    void dfs(vector<int>& coins, int index, int count, int left, int& min_count) {
        if (left == 0) {
            min_count = min(count, min_count);
            return;
        }
        if (index < 0) {
            return;
        }
        for (int k = left / coins[index]; k >= 0 && count + k < min_count; k--) {
            dfs(coins, index - 1, count + k, left - k * coins[index], min_count);
        }
    }
public:
    int coinChange(vector<int>& coins, int amount) {
        if (amount == 0) {
            return 0;
        }
        sort(coins.begin(), coins.end());
        int min_count = INT32_MAX;
        dfs(coins, coins.size() - 1, 0, amount, min_count);
        return min_count == INT32_MAX ? -1 : min_count;
    }
};

int main() {
    vector<int> input = {186, 419, 83, 408};
    Solution solution;
    int output = solution.coinChange(input, 6249);
    cout << output << endl;
}